package com.rs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.rs.dao.ZhClassesMapper;
import com.rs.dao.ZhDepartmentMapper;
import com.rs.dao.ZhPositionMapper;
import com.rs.dao.ZhUserMapper;
import com.rs.model.ZhClasses;
import com.rs.model.ZhDepartment;
import com.rs.model.ZhPosition;
import com.rs.model.ZhUser;
import com.rs.service.PublicUserMethodsService;

@Service
@Transactional
public class PublicUserMethodsImpl implements PublicUserMethodsService {
	
	@Autowired
	ZhUserMapper zhUserMapper;
	@Autowired
	ZhPositionMapper zhPositionMapper;
	@Autowired
	ZhClassesMapper zhClassesMapper;
	@Autowired
	ZhDepartmentMapper zhDepartmentMapper;

	@Override
	public ZhUser selectUserId(int id) {//yonghu详细
		// TODO Auto-generated method stub
		ZhUser zh = new ZhUser();
		zh.setuId(id);
		return zhUserMapper.selectByPrimaryKey(zh);
	}

	@Override
	public List<ZhDepartment> selectDeAll() {//得到全部部门
		// TODO Auto-generated method stub
		return zhDepartmentMapper.selectByExample();
	}

	@Override
	public List<ZhPosition> selectPoAll() {//得到全部职务
		// TODO Auto-generated method stub
		return zhPositionMapper.selectByExample();
	}

	@Override
	public List<ZhClasses> selectCaAll() {//得到全部为毕业班级
		// TODO Auto-generated method stub   Page<ZhClasses> notGraduateZhClassess();
		Page<ZhClasses> page =zhClassesMapper.notGraduateZhClassess();
		return page.getResult();
	}

	@Override
	public Integer userDel(Integer id) {//删除用户
		// TODO Auto-generated method stub
		return zhUserMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int nameRepetition(String name) {//比较昵称是否重复
		// TODO Auto-generated method stub
		ZhUser zh = new ZhUser();
		zh.setuUsername(name);
		ZhUser uu =zhUserMapper.selectByPrimaryKey(zh);
		int a = 0;
		if(uu !=null){
			a=1;
		}
		return a;
	}

	@Override
	public String selectDe(int id) {//查询部门
		// TODO Auto-generated method stub
		ZhDepartment de =zhDepartmentMapper.selectByPrimaryKey(id);
		if(de ==null){
			return "null";
		}
		return de.getDeName();
	}

	@Override
	public String selectPo(int id) {//查询职务
		// TODO Auto-generated method stub
		ZhPosition po= zhPositionMapper.selectByPrimaryKey(id);
		if(po ==null){
			return "null";
		}
		return po.getPoName();
	}
	
	@Override
	public String selectCl(int id) {//班级职务
		// TODO Auto-generated method stub
		ZhClasses po= zhClassesMapper.selectByPrimaryKey(id);
		System.out.println(po);
		if(po ==null){
			return "null";
		}
		return po.getClName();
	}

}
